﻿using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using Shop.Domain.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shop.Application.Cart
{
    public class GetCustomerInformation
    {
        private ISession _session;
        public GetCustomerInformation(ISession session)
        {
            _session = session;
        }

        public CustomerInput Do()
        {
            var str = _session.GetString("CustomerInfo");
            if (string.IsNullOrEmpty(str))
                return null;

            var customerInfo = JsonConvert.DeserializeObject<CustomerInformation>(str);
            return new CustomerInput
            {
                UserName = customerInfo.UserName,
                Email = customerInfo.Email,
                Address = customerInfo.Address,
                PhoneNumber = customerInfo.PhoneNumber,
                City = customerInfo.City,
                PostCode = customerInfo.PostCode
            };
        }
    }
}
